This XCMD will unmount and eject the specified disk. Trying to eject a non-removable disk will return an error message unless the second parameter to the XCMD is the literal string "EjectAll", in which case the XCMD will attempt to eject any disk. If you specify "EjectAll" and attempt to eject the start-up volume (the disk which has the active system folder on it) the volume will be unmounted/ejected and an error message will be returned.
It is probably wise to make sure that no files on the disk to be ejected are open before using this XCMD (see the ΓÇ£OpenFilesΓÇ¥ XFCN in this stack). Applications may behave unpredictably, and/or files may be corrupted if you remove a volume without first closing all files on it. Although the XCMD returns an error message if a file (other than the Desktop) is open on a drive which has been ejected, by then the damage may have already been done.
function DriveNumToQueElement (driveNum: integer): DrvQElPtr;
{ given a drive number, return a drive que pointer for that drive}
{ 12:32 PM 3/1/90 ec }
var
aQueElement: DrvQElPtr;
headPtr: QHdrPtr;
begin
headPtr := GetDrvQHdr;{ grab the drive que header }
if headPtr <> nil then
begin
aQueElement := DrvQElPtr(headPtr^.qHead);
while (aQueElement^.dQDrive <> driveNum) and (aQueElement <> nil) do
aQueElement := DrvQElPtr(aQueElement^.qLink);
DriveNumToQueElement := aQueElement;
end
else
DriveNumToQueElement := nil;
end;
procedure ejectDisk (paramPtr: XCmdPtr);
var
volToEject, tempVar: str255;
PB: HParamBlockRec;
errorCode: OSErr;
begin
if AskedForHelp(paramPtr, 'EjectDisk diskName, «“EjectAll”», «“noDialog:”errorGlobal»', '© 1990 Apple Computer, Inc. v.1.1, bu Eric Carlson.') then